
/* GENERATED CODE:
 *  Any modifications you make are guaranteed
 *  to be deleted when this is regenerated.
 * Please edit "PROTOCOLS" inside this directory
 *
 * Names are all upper case because of "String" and "string."
 */

using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using OWED.Network.Messages.General;
using OWED.Network.Messages;
using OWED.Network.Messages.Reply;


namespace OWED.Network.Messages
{
	public class GetComment: IProtocolItem 
	{
		User my_user;
		DiscussionID my_discussionid;
		CommentRef my_commentref;
		public GetComment (User user, DiscussionID discussionid, CommentRef commentref)
		{
			my_user = user;
			my_discussionid = discussionid;
			my_commentref = commentref;
		}
		public User User { get { return my_user; } }
		public DiscussionID DiscussionID { get { return my_discussionid; } }
		public CommentRef CommentRef { get { return my_commentref; } }


		public static new GetComment FromXml(XmlDocument xml)
		{
			XmlDocument doc;
			if (xml.SelectSingleNode("GetComment/User") != null &&
					xml.SelectSingleNode("GetComment/DiscussionID") != null &&
					xml.SelectSingleNode("GetComment/CommentRef") != null) {
				doc = new XmlDocument();
				doc.AppendChild(doc.ImportNode(xml.SelectSingleNode("GetComment/User"), true));
				User user = User.FromXml(doc);

				doc = new XmlDocument();
				doc.AppendChild(doc.ImportNode(xml.SelectSingleNode("GetComment/DiscussionID"), true));
				DiscussionID discussionid = DiscussionID.FromXml(doc);

				doc = new XmlDocument();
				doc.AppendChild(doc.ImportNode(xml.SelectSingleNode("GetComment/CommentRef"), true));
				CommentRef commentref = CommentRef.FromXml(doc);

				return new GetComment(user, discussionid, commentref);
			}
			throw new ConnectionException("Bad document supposedly of type:GetComment");
		}


		public override XmlDocument ToXml()		{
			XmlDocument doc = new XmlDocument();

			doc.AppendChild(doc.CreateElement("GetComment"));

			if (my_user != null) {
				XmlNode node;
				node = doc.ImportNode(my_user.ToXml().FirstChild, true);
				doc.FirstChild.AppendChild(node);
			}

			if (my_discussionid != null) {
				XmlNode node;
				node = doc.ImportNode(my_discussionid.ToXml().FirstChild, true);
				doc.FirstChild.AppendChild(node);
			}

			if (my_commentref != null) {
				XmlNode node;
				node = doc.ImportNode(my_commentref.ToXml().FirstChild, true);
				doc.FirstChild.AppendChild(node);
			}

			return doc;
		}
	}
}
